package com.hsyt.pms.sys.dubbo.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hsyt.pfc.support.rpc.PageResult;
import com.hsyt.pms.api.dto.system.SysDictionaryDto;
import com.hsyt.pms.api.enums.AbleStatus;
import com.hsyt.pms.api.enums.DictionaryGroup;
import com.hsyt.pms.api.vo.system.SysDictionaryVo;
import com.hsyt.pms.orm.sys.SysDictionaryDao;
import com.hsyt.pms.sys.dubbo.SysUserService;
import com.hsyt.pms.sys.dubbo.SysDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: SysDictionaryServiceImpl
 * @Description: 数据字典
 * @author wangze@hsyuntai.com
 * @date 2019年2月12日 下午2:45:51
 */
@Slf4j
@Component
@Service(version = "0.0.1", interfaceClass = SysDictionaryService.class, registry = "pms", group = "pmsSystem", timeout = 3000)
public class SysDictionaryServiceImpl implements SysDictionaryService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SysDictionaryServiceImpl.class);

    @Resource
    private SysDictionaryDao sysDictionaryDao;

    public PageResult<SysDictionaryVo> searchDictGroupPageByDto(SysDictionaryDto dto) {
        dto.setGroupCode(DictionaryGroup.DICTIONARY_GROUP.getCode());
        Page<?> page = PageHelper.startPage(dto.getPageNumber(), dto.getPageSize(), true);
        List<SysDictionaryVo> list = sysDictionaryDao.queryDictByDto(dto);
        PageResult<SysDictionaryVo> pageResult = PageResult.create(page.getTotal(), list);
        return pageResult;
    }

    public Boolean insertSysDict(SysDictionaryDto sysDictionaryDto) {
        return sysDictionaryDao.insertSysDict(sysDictionaryDto) == 1;
    }

    public Boolean updateByPrimaryKey(SysDictionaryDto sysDictionaryDto) {
        return sysDictionaryDao.updateByPrimaryKey(sysDictionaryDto) == 1;
    }

    public SysDictionaryVo getDictionary(SysDictionaryDto sysDictionaryDto) {
        return sysDictionaryDao.getDictionary(sysDictionaryDto);
    }

    public List<SysDictionaryVo> getSysDictionaryList(DictionaryGroup dg) {
        SysDictionaryDto dto = new SysDictionaryDto();
        dto.setGroupCode(dg.getCode());
        dto.setStatus(AbleStatus.ENABLED.getCode());
        return sysDictionaryDao.listSysDict(dto);
    }

    @Override
    public PageResult<SysDictionaryVo> searchPageDataByDto(SysDictionaryDto dto) {
        Page<?> page = PageHelper.startPage(dto.getPageNumber(), dto.getPageSize(), true);
        List<SysDictionaryVo> list = sysDictionaryDao.queryDictByDto(dto);
        PageResult<SysDictionaryVo> pageResult = PageResult.create(page.getTotal(), list);
        return pageResult;
    }

}
